module teapo.app.tests {
export class TestPage {
tests: TestCase[] = [];
constructor(namespace: any = teapo.app.tests,
private _queueWorkItem: (action: () => void) => void = action => setTimeout(action, 10)) {
this._loadTests(namespace);
}
private _loadTests(namespace: any) {
var byName: { [name: string]: TestCase; } = {};
var names: string[] = [];
TestPage.forEachTest(namespace, (name, test) => {
var testCase = new TestCase(name, test);
byName[name] = testCase;
names.push(name);
});
names.sort();
names.forEach(name => {
var testCase = byName[name];
this.tests.push(testCase);
});
}
static forEachTest(namespace: any, callback: (name: string, test: () => void) => void) {
for (var k in namespace) if (namespace.hasOwnProperty(k)) {
var t = namespace[k];
if (typeof (t) === 'function') {
callback(k, t);
}
}
}
}
}